<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/general.css" type="text/css" />
<link rel="stylesheet" href="css/layout.css" type="text/css" />
<title>pagetest</title>

<style type="text/css">
#abc{
margin-left:20px;
margin-top:20px;
}

li{
width:19px;
height:22px;
background:pink;
margin-right:5px;
line-height:22px;

}

li.unhover{
background-color: #F2F2F2;
border: 1px solid #999;
border-top: 1px solid #DDD;
border-left: 1px solid #DDD;
}

li.hover{
background-color: #F2F2F2;
border: 1px solid #999;
border-bottom: 1px solid #DDD;
border-right: 1px solid #DDD;
}

li.selected{
border:1px solid;
color: white;
font-weight: bold;
background: #58595B;
}
</style>

</head>

<body>

<div id="abc">
<ul>
<?php
$curpage = $_GET['page'];
$firstpage=1;
$lastpage=15;

$hasFirstPage = true;
$hasLastPage = true;
$hasPrePage = true;
$hasNextPage =true;

$pagenum = '';

for($i=4; $i>=1; $i--)
{
	$leftpage = $curpage-$i;
	if( $leftpage <= 0 )
	{
		continue;
	}
	if( $leftpage == 1 )
		$hasFirstPage = false;
	$pagenum = $pagenum.'<a href=""><li class="unhover">'.$leftpage.'</li></a>';

}

$pagenum = $pagenum.'<a href=""><li class="selected">'.$curpage.'</li></a>';

for( $i=1; $i<=4; $i++ )
{
	$rightpage = $curpage+$i;
	if( $rightpage > $lastpage )
		break;

	$pagenum = $pagenum.'<a href=""><li class="unhover">'.$rightpage.'</li></a>';

	if( $rightpage == $lastpage )
		$hasLastPage = false;


}

if( $curpage == 1 )
    $hasFirstPage = false;
if( $curpage == $lastpage )
    $hasLastPage = false;

if( $curpage == 1 )
    $hasPrePage = false;

if( $curpage == $lastpage )
    $hasNextPage = false;

if( $hasFirstPage == true )
{
	$pagenum = '<a href=""><li class="unhover" style="background-color:#F2F2F2;">首页</li></a>'.$pagenum;
}

if( $hasLastPage == true )
{
	$pagenum = $pagenum.'<a href=""><li class="unhover" style="background-color:#F2F2F2;">尾页</li></a>';
}

if( $hasPrePage == true )
{
	$pagenum = '<a href=""><li class="unhover" style="background-color:#F2F2F2;">上一页</li></a>'.$pagenum;
}

if( $hasNextPage ==true )
{
	$pagenum = $pagenum.'<a href=""><li class="unhover" style="background-color:#F2F2F2;">下一页</li></a>';
}

echo $pagenum;
?>
</ul>
</div>
</body>
</html>